using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using EkRtfBase;

namespace WindowsApplication11
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void NewUserFunctionCode(object Sender, EkRtfFunc.EkUDFEventArgs e)
        {
          // **** This is NewUserFunction ****
          string s;
          s = "";
 
         //if report variable or constant passed as function argument
         if (e.Args[0] is EkReportVariable)
            {
            s = ((EkReportVariable)e.Args[0]).AsString;
            }

         //if data field passed as function argument
         if (e.Args[0] is EkDataField)
            {
            s = Convert.ToString(((EkDataField)e.Args[0]).Value);
            }

         //The result
         ((EkReportVariable)e.UDFResult).AsString=s;
        }

        private void button1_Click(object sender, EventArgs e)
        {
         OleDbDataAdapter customerAdapter;
         DataSet _ds;
         
         // connect to access database
         OleDbConnection cn;
         cn = new OleDbConnection();
         cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=nwind.mdb";
         cn.Open();

         // create an oledb adapter containing a wildcard query for each table we are interested in
         customerAdapter = new OleDbDataAdapter("SELECT * from Customers", cn);

         // fill a dataset with all of the tables we are interested in using the adapters
         _ds = new DataSet();
         customerAdapter.Fill(_ds, "Customers");

         ekRtf1.ReportData.Clear();
         ekRtf1.ReportData.Add(_ds.Tables["Customers"], "Customers");
         ekRtf1.ExecuteOpen();

         cn.Close();
        }
    }
}